<!DOCTYPE html><html><head><title>第一周正式课–课后作业（2）</title><meta charset='utf-8'><link href='https://cdn.maxiang.io/res-min/themes/marxico.css' rel='stylesheet'><style>
.note-content  {font-family: "Helvetica Neue", Arial, "Hiragino Sans GB", STHeiti, "Microsoft YaHei", "WenQuanYi Micro Hei", SimSun, Song, sans-serif;}

</style></head><body><div id='preview-contents' class='note-content'>
                        
                    



<h3 id="第一周正式课课后作业2">第一周正式课–课后作业（2）</h3>

<ol start="1"><li rel="1"><p>写出下面代码输出的结果（画图）</p></li>
</ol>

<pre class="prettyprint hljs-dark"><code class="language-javascript hljs"><div class="hljs-line"><span class="hljs-keyword">var</span> i = <span class="hljs-number">20</span>;
</div><div class="hljs-line"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">fn</span>(<span class="hljs-params"></span>) </span>{
</div><div class="hljs-line">    i -= <span class="hljs-number">2</span>;
</div><div class="hljs-line">    <span class="hljs-keyword">var</span> i = <span class="hljs-number">10</span>;
</div><div class="hljs-line">    <span class="hljs-keyword">return</span> <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">n</span>) </span>{
</div><div class="hljs-line">        <span class="hljs-built_in">console</span>.log((++i) - n);
</div><div class="hljs-line">    }
</div><div class="hljs-line">}
</div><div class="hljs-line"><span class="hljs-keyword">var</span> f = fn();
</div><div class="hljs-line">f(<span class="hljs-number">1</span>);
</div><div class="hljs-line">f(<span class="hljs-number">2</span>);
</div><div class="hljs-line">fn()(<span class="hljs-number">3</span>);
</div><div class="hljs-line">fn()(<span class="hljs-number">4</span>);
</div><div class="hljs-line">f(<span class="hljs-number">5</span>);
</div><div class="hljs-line"><span class="hljs-built_in">console</span>.log(i);
</div></code></pre>

<ol start="2"><li rel="2"><p>写出下面代码输出的结果  （画图）</p></li>
</ol>

<pre class="prettyprint hljs-dark"><code class="language-javascript hljs"><div class="hljs-line"><span class="hljs-keyword">let</span> x = <span class="hljs-number">5</span>;
</div><div class="hljs-line"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">fn</span>(<span class="hljs-params">x</span>) </span>{
</div><div class="hljs-line">    <span class="hljs-keyword">return</span> <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">y</span>) </span>{
</div><div class="hljs-line">        <span class="hljs-built_in">console</span>.log(y + (++x));
</div><div class="hljs-line">    }
</div><div class="hljs-line">}
</div><div class="hljs-line"><span class="hljs-keyword">let</span> f = fn(<span class="hljs-number">6</span>);
</div><div class="hljs-line">f(<span class="hljs-number">7</span>);
</div><div class="hljs-line">fn(<span class="hljs-number">8</span>)(<span class="hljs-number">9</span>);
</div><div class="hljs-line">f(<span class="hljs-number">10</span>);
</div><div class="hljs-line"><span class="hljs-built_in">console</span>.log(x);
</div></code></pre>

<ol start="3"><li rel="3"><p>写出下面代码输出的结果  （画图）</p></li>
</ol>

<pre class="prettyprint hljs-dark"><code class="language-javascript hljs"><div class="hljs-line"><span class="hljs-keyword">let</span> x = <span class="hljs-number">5</span>;
</div><div class="hljs-line"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">fn</span>(<span class="hljs-params"></span>) </span>{
</div><div class="hljs-line">    <span class="hljs-keyword">return</span> <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">y</span>) </span>{
</div><div class="hljs-line">        <span class="hljs-built_in">console</span>.log(y + (++x));
</div><div class="hljs-line">    }
</div><div class="hljs-line">}
</div><div class="hljs-line"><span class="hljs-keyword">let</span> f = fn(<span class="hljs-number">6</span>);
</div><div class="hljs-line">f(<span class="hljs-number">7</span>);
</div><div class="hljs-line">fn(<span class="hljs-number">8</span>)(<span class="hljs-number">9</span>);
</div><div class="hljs-line">f(<span class="hljs-number">10</span>);
</div><div class="hljs-line"><span class="hljs-built_in">console</span>.log(x);
</div></code></pre>

<ol start="4"><li rel="4"><p>写出下面代码输出的结果   （画图）</p></li>
</ol>

<pre class="prettyprint hljs-dark"><code class="language-javascript hljs"><div class="hljs-line"><span class="hljs-keyword">let</span> a=<span class="hljs-number">0</span>,
</div><div class="hljs-line">    b=<span class="hljs-number">0</span>;
</div><div class="hljs-line"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">A</span>(<span class="hljs-params">a</span>)</span>{
</div><div class="hljs-line">    A=<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">b</span>)</span>{
</div><div class="hljs-line">        alert(a+b++);
</div><div class="hljs-line">    };
</div><div class="hljs-line">    alert(a++);
</div><div class="hljs-line">}
</div><div class="hljs-line">A(<span class="hljs-number">1</span>);
</div><div class="hljs-line">A(<span class="hljs-number">2</span>);
</div></code></pre>

<ol start="5"><li rel="5"><p>写出下面代码输出的结果   （画图）</p></li>
</ol>

<pre class="prettyprint hljs-dark"><code class="language-javascript hljs"><div class="hljs-line"><span class="hljs-keyword">var</span> n=<span class="hljs-number">0</span>; 
</div><div class="hljs-line"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">a</span>(<span class="hljs-params"></span>)</span>{
</div><div class="hljs-line">    <span class="hljs-keyword">var</span> n=<span class="hljs-number">10</span>; 
</div><div class="hljs-line">    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">b</span>(<span class="hljs-params"></span>)</span>{
</div><div class="hljs-line">        n++; 
</div><div class="hljs-line">        <span class="hljs-built_in">console</span>.log(n); 
</div><div class="hljs-line">    }
</div><div class="hljs-line">    b();
</div><div class="hljs-line">    <span class="hljs-keyword">return</span> b; 
</div><div class="hljs-line">}
</div><div class="hljs-line"><span class="hljs-keyword">var</span> c=a();
</div><div class="hljs-line">c(); 
</div><div class="hljs-line"><span class="hljs-built_in">console</span>.log(n);
</div></code></pre>

<ol start="6"><li rel="6"><p>写出下面代码输出的结果   （画图）</p></li>
</ol>

<pre class="prettyprint hljs-dark"><code class="language-javascript hljs"><div class="hljs-line"><span class="hljs-keyword">var</span> test = (<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">i</span>)</span>{
</div><div class="hljs-line">    <span class="hljs-keyword">return</span> <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{
</div><div class="hljs-line">        alert(i*=<span class="hljs-number">2</span>);
</div><div class="hljs-line">    }
</div><div class="hljs-line">})(<span class="hljs-number">2</span>);
</div><div class="hljs-line">test(<span class="hljs-number">5</span>);
</div></code></pre></div></body></html>